package com.hgxd.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hgxd.annotation.OperationLogAnnotation;
import com.hgxd.service.IElectricityBrandService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

import javax.annotation.Resource;
import java.util.List;

import com.hgxd.result.Result;

import com.hgxd.entity.pojo.ElectricityBrand;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 电表品牌表 前端控制器
 * </p>
 *
 * @author fsd
 * @since 2023-10-18
 */
@Api(tags = "电表品牌表")
@RestController
@RequestMapping("/api/electricity-brand")
@CrossOrigin
public class ElectricityBrandController {
    @Resource(name = "ElectricityBrandServiceImpl")
    private IElectricityBrandService electricityBrandService;

    /**
     * 新增
     */
    @PostMapping("/save")
    @ApiOperation(value = "新增电表品牌表", notes = "新增电表品牌表")
    @ApiImplicitParam(name = "electricityBrand", value = "电表品牌实体类")
    @OperationLogAnnotation(operModule = "电表品牌表-新增电表品牌表", operType = "新增", operContent = "新增电表品牌表")
    public Result<Boolean> insert(@RequestBody ElectricityBrand electricityBrand) {
        return Result.ok(electricityBrandService.save(electricityBrand));
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperation(value = "修改电表品牌表", notes = "修改电表品牌表")
    @ApiImplicitParam(name = "electricityBrand", value = "电表品牌实体类")
    @OperationLogAnnotation(operModule = "电表品牌表-修改电表品牌表", operType = "修改", operContent = "修改电表品牌表")
    public Result<Boolean> update(@RequestBody ElectricityBrand electricityBrand) {
        return Result.ok(electricityBrandService.updateById(electricityBrand));
    }

    /**
     * 批量删除
     */
    @PostMapping("/del/batch")
    @ApiOperation(value = "批量删除电表品牌表", notes = "批量删除电表品牌表")
    @ApiImplicitParam(name = "ids", value = "id的数组")
    @OperationLogAnnotation(operModule = "电表品牌表-批量删除", operType = "删除", operContent = "批量删除电表品牌表")
    public Result<Boolean> deleteBatch(@RequestBody List<Integer> ids) {
        return Result.ok(electricityBrandService.removeByIds(ids));
    }

    /**
     * 查询全部
     */
    @GetMapping("/getAll")
    @ApiOperation(value = "查询全部电表品牌表", notes = "查询全部电表品牌表")
    @OperationLogAnnotation(operModule = "电表品牌表-查询全部电表品牌表", operType = "查询", operContent = "查询全部电表品牌表")
    public Result<List<ElectricityBrand>> findAll() {
        return Result.ok(electricityBrandService.list());
    }

    /**
     * 根据id查询一个
     */
    @GetMapping("getById/{id}")
    @ApiOperation(value = "根据id查询一个电表品牌表", notes = "根据id查询一个电表品牌表")
    @ApiImplicitParam(name = "id", value = "id")
    @OperationLogAnnotation(operModule = "电表品牌表-根据id查询一个电表品牌表", operType = "查询", operContent = "根据id查询一个电表品牌表")
    public Result<ElectricityBrand> findOne(@PathVariable Integer id) {
        return Result.ok(electricityBrandService.getById(id));
    }

    /**
     * 分页模糊查询
     */
    @GetMapping("/get/page")
    @ApiOperation(value = "分页模糊查询电表品牌表", notes = "分页模糊查询电表品牌表")
    @OperationLogAnnotation(operModule = "电表品牌表-分页模糊查询电表品牌表", operType = "查询", operContent = "分页模糊查询电表品牌表")
    public Result<Page<ElectricityBrand>> findPage(@RequestParam Integer pageNum,
                                                   @RequestParam Integer pageSize) {
        QueryWrapper<ElectricityBrand> queryWrapper = new QueryWrapper<>();
        // 倒序查询
        queryWrapper.orderByDesc("id");
        return Result.ok(electricityBrandService.page(new Page<>(pageNum, pageSize), queryWrapper));
    }
}

